package com.mingqijia.gassafety.console.controller;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.shared.constant.PageColumnConst;
import com.mingqijia.gassafety.shared.utils.HeaderUtil;
import com.mingqijia.gassafety.shared.utils.commonUtils.PageUtil;
import com.mingqijia.gassafety.webserver.request.InformRecordRequest;
import com.mingqijia.gassafety.webserver.request.WarningRecordDetailRequest;
import com.mingqijia.gassafety.webserver.request.WarningRecordInfoRequest;
import com.mingqijia.gassafety.webserver.request.WarningRecordListRequest;
import com.mingqijia.gassafety.webserver.response.WarningRecordDetailResponse;
import com.mingqijia.gassafety.webserver.response.WarningRecordInfoResponse;
import com.mingqijia.gassafety.webserver.response.WarningRecordResponse;
import com.mingqijia.gassafety.webserver.service.WarningRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

import static com.mingqijia.gassafety.shared.constant.Constants.BIND_CHANNEL_ASST;
import static com.mingqijia.gassafety.shared.constant.Constants.BIND_CHANNEL_GAS;
import static com.mingqijia.gassafety.shared.constant.PageColumnConst.*;
import static com.mingqijia.gassafety.shared.constant.PageColumnConst.gasConsumerListIndices;

/**
 * <p>
 *
 * @author wanghai
 * @since 2022-03-10
 */

@Slf4j
@Api(tags = "报警-通知记录")
@RestController(value = "WarningRecordController")
@RequestMapping("/business/v1/warning/record")
public class WarningRecordController {
    @Autowired
    WarningRecordService warningRecordService;
    @Autowired
    HeaderUtil headerUtil;

    @ApiOperation("通知记录列表")
    @RequestMapping(value = "list", method = RequestMethod.POST)
    public CommonResponse<PageUtil<WarningRecordResponse>> recordList(@RequestBody WarningRecordListRequest request) {
        request.setTemplateType(headerUtil.getTemplateType());
        PageUtil<WarningRecordResponse> list = warningRecordService.getList(request);
        if (BIND_CHANNEL_ASST == request.getTemplateType()) {
            list.setColumns(PageColumnConst.add(asstWarningRecodeListTitles, asstWarningRecodeListIndices));
        } else if (BIND_CHANNEL_GAS == request.getTemplateType()) {
            list.setColumns(PageColumnConst.add(gasWarningRecodeListTitles, gasWarningRecodeListIndices));
        }
        return CommonResponse.success(list);
    }

    @ApiOperation("通知记录-详情相关信息")
    @RequestMapping(value = "detail", method = RequestMethod.POST)
    public CommonResponse<WarningRecordDetailResponse> recordDetailInfo(@RequestBody @Valid WarningRecordDetailRequest request) {
        return CommonResponse.success(warningRecordService.recordDetailInfo(request));
    }


    @ApiOperation("通知记录-详情列表")
    @RequestMapping(value = "detail/list", method = RequestMethod.POST)
    public CommonResponse<PageUtil<WarningRecordInfoResponse>> recordDetailList(@RequestBody @Valid WarningRecordInfoRequest request) {

        return CommonResponse.success(warningRecordService.recordDetailList(request));
    }
}


